cmake_minimum_required(VERSION 3.13)
project(vvxfce4-session)

set(IS_ALONE_COMPILE TRUE)
if (NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
       set(IS_ALONE_COMPILE FALSE)
endif()

set(HELPER_PATH_PREFIX "lib")

include(cmake/my_utils.cmake)

my_check_header_exists_and_define_macro("sys/types.h")
my_check_header_exists_and_define_macro("sys/wait.h")
my_check_header_exists_and_define_macro("sys/stat.h")
my_check_header_exists_and_define_macro("errno.h")
my_check_header_exists_and_define_macro("fcntl.h")
my_check_header_exists_and_define_macro("memory.h")
my_check_header_exists_and_define_macro("signal.h")
my_check_header_exists_and_define_macro("stdlib.h")
my_check_header_exists_and_define_macro("string.h")
my_check_header_exists_and_define_macro("unistd.h")
my_check_function_exists_and_define_macro(gethostname HAVE_GETHOSTNAME)

find_package(PkgConfig)
if (${IS_ALONE_COMPILE})
pkg_check_modules(GLIB IMPORTED_TARGET glib-2.0)
pkg_check_modules(GIO IMPORTED_TARGET gio-2.0)
pkg_check_modules(GMODULE IMPORTED_TARGET gmodule-2.0)
pkg_check_modules(XFCE4_UI IMPORTED_TARGET libxfce4ui-2)
pkg_check_modules(XFCE4_UTIL IMPORTED_TARGET libxfce4util-1.0)
pkg_check_modules(XFCONF IMPORTED_TARGET libxfconf-0)
pkg_check_modules(WNCK IMPORTED_TARGET libwnck-3.0)
endif()
pkg_check_modules(X11 IMPORTED_TARGET x11)
pkg_check_modules(POLKIT_GOBJECT IMPORTED_TARGET polkit-gobject-1)
pkg_check_modules(SM IMPORTED_TARGET sm)
pkg_check_modules(ICE IMPORTED_TARGET ice)

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/config.h "")
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

add_library(vvxfce4-session-macros-interface
        INTERFACE
)

set(PACKAGE_LOCALE_DIR ${CMAKE_INSTALL_PREFIX}/share/locale)

target_compile_definitions(vvxfce4-session-macros-interface
        INTERFACE
        PACKAGE="${PROJECT_NAME}"
        VERSION="${PROJECT_VERSION}"
        PACKAGE_VERSION="${PROJECT_VERSION}"
        ICEAUTH_CMD="${ICEAUTH_CMD}"
        REVISION="${PROJECT_VERSION}"
        DATADIR="${CMAKE_INSTALL_DATADIR}"
        SYSCONFDIR="${CMAKE_INSTALL_SYSCONFDIR}"
        GETTEXT_PACKAGE="${PROJECT_NAME}"
        PACKAGE_LOCALE_DIR="${PACKAGE_LOCALE_DIR}"
        PACKAGE_NAME="${PACKAGE}"
        HELPERDIR="${CMAKE_INSTALL_PREFIX}/lib" #default
        PACKAGE_DATADIR="${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}"
        G_LOG_DOMAIN="${PROJECT_NAME}"
        XFSM_SHUTDOWN_HELPER_CMD="${CMAKE_INSTALL_PREFIX}/${HELPER_PATH_PREFIX}/xfce4/session/xfsm-shutdown-helper"
        DBUS_API_SUBJECT_TO_CHANGE
        WNCK_I_KNOW_THIS_IS_UNSTABLE
        UPOWER_ENABLE_DEPRECATED
        PACKAGE_BUGREPORT="https://gitlab.xfce.org/xfce/xfce4-session"
)

add_subdirectory(libxfsm)
# add_subdirectory(doc)
# add_subdirectory(icons)
add_subdirectory(po)
add_subdirectory(settings)
add_subdirectory(scripts)
add_subdirectory(xfce4-session)
add_subdirectory(xfce4-session-logout)
add_subdirectory(xfsm-shutdown-helper)



set(startvvxfce4 ${CMAKE_INSTALL_PREFIX}/bin/startvvxfce4)
configure_file(
        ${CMAKE_CURRENT_SOURCE_DIR}/vvxfce.desktop.in
        ${CMAKE_CURRENT_BINARY_DIR}/vvxfce.desktop
        @ONLY
)

install(FILES
        ${CMAKE_CURRENT_BINARY_DIR}/vvxfce.desktop
        DESTINATION /usr/share/xsessions
)

#desktopdir = $(XSESSION_PREFIX)/share/xsessions
#desktop_in_files = xfce.desktop.in
#desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
#@INTLTOOL_DESKTOP_RULE@
#
#distuninstallcheck_listfiles = 						\
#	find . -type f -print | grep -v ./share/icons/hicolor/icon-theme.cache
#
#EXTRA_DIST =								\
#	BUGS								\
#	README.md							\
#	intltool-extract.in						\
#	intltool-merge.in						\
#	intltool-update.in						\
#	$(config_DATA)							\
#	$(desktop_in_files)
#
#DISTCLEANFILES =							\
#	intltool-extract						\
#	intltool-merge							\
#	intltool-update							\
#	po/.intltool-merge-cache.lock			\
#	$(desktop_DATA)
#
#distclean-local:
#	rm -rf *.cache *~
#
#.PHONY: ChangeLog
#
#ChangeLog: Makefile
#	(GIT_DIR=$(top_srcdir)/.git git log > .changelog.tmp \
#	&& mv .changelog.tmp ChangeLog; rm -f .changelog.tmp) \
#	|| (touch ChangeLog; echo 'Git directory not found: installing possibly empty changelog.' >&2)
#
#dist-hook: ChangeLog
#
#DISTCHECK_CONFIGURE_FLAGS =						\
#	--with-xsession-prefix=/tmp/$(PACKAGE)-distcheck
#
## vi:set ts=8 sw=8 noet ai nocindent:
#
